package com.yangye.picommon.utils;

import org.apache.commons.io.FileUtils;

import java.io.*;

/**
 * Created by youngyeah on 2019/9/23 0023
 */
public class FileUtil {

	public static File inputStreamToFile(InputStream inputStream, String name) throws IOException {
		File file = new File(System.getProperty("java.io.tmpdir") + name);
		if (file.exists()) {
			return file;
		}
		OutputStream os = new FileOutputStream(file);
		int bytesRead = 0;
		byte[] buffer = new byte[8192];
		while ((bytesRead = inputStream.read(buffer, 0, 8192)) != -1) {
			os.write(buffer, 0, bytesRead);
		}
		os.close();
		inputStream.close();
		return file;
	}
}
